import Vue from 'vue'
import VueRouter from 'vue-router'
// 登录注册
import login from '../views/login/index.vue'
// 主页
import index from '../views/index/index.vue'
// 主页的嵌套页面
import chart from '../views/index/chart/index.vue'
import company from '../views/index/company/index.vue'
import question from '../views/index/question/index.vue'
import user from '../views/index/user/index.vue'
import subject from '../views/index/subject/index.vue'
import notFound from '../views/404/index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: login,
    meta: {
      title: '登录页'
    }
  },
  {
    path: '/index',
    component: index,
    redirect: '/index/chart',
    children: [
      {
        path: 'user',
        component: user,
        meta: {
          title: '用户列表'
        }
      },
      {
        path: 'chart',
        component: chart,
        meta: {
          title: '数据概览'
        }
      },
      {
        path: 'company',
        component: company,
        meta: {
          title: '企业列表'
        }
      },
      {
        path: 'question',
        component: question,
        meta: {
          title: '题库列表'
        }
      },
      {
        path: 'subject',
        component: subject,
        meta: {
          title: '学科列表'
        }
      }
    ]
  },
  {
    path: '*',
    component: notFound,
    meta: {
      title: '404!Not Found!'
    }
  }
]

const router = new VueRouter({
  routes
})

router.afterEach((to, from) => {
  document.title = to.meta.title
})

export default router
